Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

deMemory_priv.hpp

Go to the documentation of this file.
00001 ///////////////////////////////////////////////////////////////////////////////
00002 /// @file deMemory_priv.hpp
00003 ///
00004 /// @brief Destiny3D Memory Manager
00005 ///
00006 /// @author Lightning
00007 ///
00008 /// This file is the intellectual property of Novus Delta, LLC.. Usage of the
00009 /// contents of this file is subject to the Destiny3D Member License which
00010 /// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
00011 ///
00012 /// This file is distributed "AS IS" without warranty of any kind.  Novus
00013 /// Delta, LLC. does not guarantee the fitness of the contents of this file
00014 /// for any particular purpose.
00015 ///
00016 /// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
00017 ///
00018 /// <hr>
00019 ///                                 Change History
00020 /// <hr>
00021 ///
00022 /// @date Feb 2001
00023 /// @author Lightning
00024 /// @remarks Creation
00025 ///
00026 /// @date Oct 2001
00027 /// @author Hootie
00028 /// @remarks Started Conversion to C++
00029 ///
00030 /// @date Oct 2002
00031 /// @author Lightning
00032 /// @remarks Scrapped old, started from scratch
00033 ///
00034 ///////////////////////////////////////////////////////////////////////////////
00035 
00036 #ifndef DEMEMORY_PRIV_HPP
00037 #define DEMEMORY_PRIV_HPP
00038 
00039 //include the headers
00040 #include "deGlobalTypes.hpp"
00041 #include "Functions/Functions.hpp"
00042 #include "deMemory.hpp"
00043 #include "RedBlackTree.hpp"
00044 
00045 //a global header we need
00046 //#include <cstdio>
00047 
00048 #ifdef _WIN32
00049     //need the windows header for memory functions
00050     #include <windows.h>
00051 #endif
00052 
00053 class deMemoryManager : public IdeMemoryManager
00054 {
00055     public:
00056         deMemoryManager(char *ConfigFile);
00057         ~deMemoryManager();
00058         
00059         ///function to see if we initialized properly
00060         deBoolean IsInitialized();
00061 
00062         //all the functions that are used for overridding
00063         void * Malloc(unsigned int Size, MallocType Type, const char *File, long Line);
00064         void Free(void *Ptr, FreeType Type, const char *File, long Line);
00065         void * MemCpy(void *To, const void *From, unsigned int Size, const char *File, long Line);
00066         void * MemSet(void *To, int Value, unsigned int Size, const char *File, long Line);
00067 
00068     private:
00069         //internal structure for alloc info
00070         typedef struct AllocStruct
00071         {
00072             char *                          File;
00073             DWORD                           Line;
00074             IdeMemoryManager::MallocType    AllocType;
00075         } AllocStruct;
00076         
00077         //internal structure storing each real allocation done
00078         typedef struct RealAllocStruct
00079         {
00080             void *                      Ptr;
00081             DWORD                       Size;
00082             struct RealAllocStruct *    Next;
00083         } RealAllocStruct;
00084 
00085         deBoolean           Initialized;        //did we init correctly
00086         RedBlackNode *      RootFreeNode;       //root of the free nodes
00087         RedBlackNode *      RootAllocNode;      //root of the alloc nodes
00088         RealAllocStruct *   RootRealAllocList;  //root of the real allocations
00089 
00090         //some private functions
00091         void CheckMemoryLeaks();
00092         RedBlackNode *AllocRealMem(DWORD *Size);
00093         void ReleaseAllRealAllocMem();
00094         void OutputMemLeak(RedBlackNode *LeakAlloc);
00095 };
00096 
00097 
00098 //some defines that are used in the memory manager internally
00099 #define Round64k(Val) ((Val + 0x0000FFFF) & 0xFFFF0000)
00100 #define Round4(Val) ((Val + 3) & 0xFFFFFFFC)
00101 
00102 
00103 //if in windows, define the allocations for windows
00104 #ifdef _WIN32
00105 
00106 //some inline functions for setting what to use on real allocations and free's
00107 static inline void *RealAlloc(DWORD *Size)
00108 {
00109     //make sure we are allocating in multiples of 64k
00110     *Size = Round64k(*Size);
00111 
00112     //now allocate it
00113     return VirtualAlloc(NULL, *Size, MEM_COMMIT, PAGE_READWRITE);
00114 }
00115 
00116 static inline deBoolean RealFree(void *Ptr)
00117 {
00118     //free the real memory that was allocated
00119     return VirtualFree(Ptr, 0, MEM_RELEASE);
00120 }
00121 
00122 #endif  //_WIN32
00123 
00124 #endif

Generated on Mon Sep 12 19:58:31 2005 for Destiny3D by doxygen1.3-rc3